package com.ruoyi.web.controller.api.user;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.POrder;
import com.ruoyi.system.service.IPOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "订单控制器", tags = {"我的咨询订单"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/store/userOrder")
public class POrderApiController extends BaseController {

    private final IPOrderService ipOrderService;

    @ApiOperation("查询订单列表")
    @GetMapping("/list")
    public TableDataInfo<POrder> list(@RequestParam("orderStatus") String orderStatus, PageQuery pageQuery) {
        return this.ipOrderService.list(orderStatus, pageQuery);
    }

    @ApiOperation("订单详情")
    @GetMapping("/orderDetail")
    public R<POrder> orderDetail(@RequestParam("orderNo") String orderNo) {
        return R.ok(this.ipOrderService.orderDetail(orderNo));
    }

    @ApiOperation("取消订单")
    @GetMapping("/cancellationOrder")
    public R cancellationOrder(@RequestParam("orderNo") String orderNo) {
        POrder pOrder = this.ipOrderService.orderFontDetail(orderNo);
        this.ipOrderService.cancelOrder(pOrder);
        return R.ok();
    }
}
